<!--
 * @Author: hucc
 * @Date: 2021-10-08 16:51:37
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-08 20:17:06
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue列表渲染</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js"></script>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in categories">
                索引：{{index}} 编号：{{item.id}} 名称：{{item.name}}
            </li>
        </ul>
    </div>
    <script>
        let vm = new Vue({
            //当前vue实例的配置项
            el: '#app',
            data: {
                categories: []
            },
            methods: {
                findAllCategories() {
                    //vue中把data里面的数据单拎出来进行封装了，所以不用写this.data.categories
                    //这里的this就是指代data
                    this.categories = [{
                        id: 1,
                        name: '校园新闻'
                    }, {
                        id: 2,
                        name: '娱乐新闻'
                    }, {
                        id: 3,
                        name: '热点聚焦'
                    }, {
                        id: 4,
                        name: '体坛赛事'
                    }]
                }
            },
            //methods:{}和created(){}是同一级别
            created() {
                this.findAllCategories();
            }

        })
    </script>
</body>

</html>